﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
//using Microsoft.VisualBasic;

namespace WEB_IUS.Clases
{
    public partial class PaginaComun : System.Web.UI.Page
    {


        public String Oper
        {
            get { return (string)ViewState["Oper"]; }
            set { ViewState["Oper"] = value; }
        }

        public String Pk1
        {
            get { return (string)ViewState["Pk1"]; }
            set { ViewState["Pk1"] = value; }
        }

        
        public String Pk2
        {
            get { return (string)ViewState["Pk2"]; }
            set { ViewState["Pk2"] = value; }
        }

        
        public String Pk3
        {
            get { return (string)ViewState["Pk3"]; }
            set { ViewState["Pk3"] = value; }
        }
        public void ExportGridView(GridView grd, string Archivo = "Export")
        {
            string attachment = string.Format("attachment; filename={0}.xls", Archivo);
            Response.ClearContent();
            Response.AddHeader("content-disposition", attachment);
            Response.ContentType = "application/ms-excel";
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            grd.RenderControl(htw);
            Response.Write(sw.ToString());
            Response.End();
        }
        public void ExportGridViewBody(GridView grd)
        {
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            grd.RenderControl(htw);
            Response.Write(sw.ToString());
        }
        public void ExportDataListBody(DataList dl)
        {
            StringWriter sw = new StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            dl.RenderControl(htw);
            Response.Write(sw.ToString());
        }
        public void ExportGridViewIni(string Archivo = "Export")
        {
            string attachment = string.Format("attachment; filename={0}.xls", Archivo);
            Response.ClearContent();
            Response.AddHeader("content-disposition", attachment);
            Response.ContentType = "application/ms-excel";
        }
        public void ExportGridViewWrite(string StrHtml)
        {
            Response.Write(StrHtml);
        }
        public void ExportGridViewFin()
        {
            Response.End();
        }

        public void Redireccionar_Pagina(string Url)
        {
            Response.Redirect("~" + Url);
        }

        public void Redireccionar_Pagina2(string Url)
        {
            Response.Redirect(this.RUTA_VIRTUAL() + Url);
        }

        private string RUTA_VIRTUAL()
        {
            return ConfigurationManager.AppSettings["VIRTUAL"].ToString();
        }

        public string GUID()
        {
            return System.Guid.NewGuid().ToString();
        }

        public void CerrarForm()
        {
            Response.Redirect("~/default.aspx");
        }

        public void Deshabilitar_Atras()
        {
            //Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache)
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.Cache.SetAllowResponseInBrowserHistory(false);
            Response.Cache.SetNoStore();
            Response.AddHeader("Pragma", "no-cache");

        }

        private void Page_Load(object sender, System.EventArgs e)
        {
            Response.CacheControl = "Private";
            //this.Title = Titulo;
            if (!this.IsPostBack) {
                this.Oper = "nuevo";
            }
            

        }

        protected void MsgBox(ref Label msg, bool lError, int alto = 50, int ancho = 600)
        {
            //msg.Height = alto
            //msg.Width = ancho
            //msg.Height = "100%"
            msg.Visible = true;
            msg.Text = "<P style='text-align:justify;'>" + msg.Text + "</P>";
            //msg.CssClass = IIf(lError = True, "NotOk", "Ok")
            //msg.ForeColor = IIf(lError = True, Drawing.Color.Red, Drawing.Color.Blue)
            if (lError == true)
            {
                MsgBoxError(ref msg, lError);
            }
            else
            {
                MsgBoxExito(ref msg, lError);
            }

        }

        protected void MsgBoxLimpiar(ref Label msg)
        {
            msg.CssClass = "";
            msg.Text = "";
        }

        protected void MsgBoxAlert(ref Label msg, bool lError, int alto = 50, int ancho = 600)
        {
            msg.CssClass = "alerta";
        }

        protected void MsgBoxInfo(ref Label msg, bool lError, int alto = 50, int ancho = 600)
        {
            msg.CssClass = "infor";
        }

        protected void MsgBoxExito(ref Label msg, bool lError, int alto = 50, int ancho = 600)
        {
            msg.CssClass = "exito";
        }
        protected void MsgBoxError(ref Label msg, bool lError, int alto = 50, int ancho = 600)
        {
            msg.CssClass = "error";
        }

        protected void MsgBoxV(ref Label msg, bool lError)
        {
            msg.Height = 100;
            msg.Width = 600;
            msg.CssClass = (lError == true ? "NotOk" : "Ok");
        }
        public static string ResolverURL(string URL)
        {
            PaginaComun p = new PaginaComun();
            return p.ResolveUrl(@URL);
        }
    }
}